package com.hd.tiyu.yuejian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.tiyu.yuejian.Activity.ActacteActivity;
import com.hd.tiyu.yuejian.Fragment.HuodongFragment;
import com.hd.tiyu.yuejian.JavaBean.Activity;
import com.hd.tiyu.yuejian.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/9/29.
 */

public class HuodongAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Activity> mDataList;
    private LayoutInflater mLayoutInflater;

    public HuodongAdapter(Context mContext,List<Activity> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView name,number;
        ImageView img;

        public ViewHolder(View itemView) {
            super(itemView);
            name=itemView.findViewById(R.id.huodong_name);
            number=itemView.findViewById(R.id.huodong_nab);
            img=itemView.findViewById(R.id.huodong_img);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=mLayoutInflater.from(parent.getContext()).inflate(R.layout.huodonglist,parent,false);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Activity data=mDataList.get(position);
        if(data!=null){
            ViewHolder viewHolder=(ViewHolder) holder;
            viewHolder.name.setText(data.getActivity_name());
            viewHolder.number.setText(data.getHits());
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+data.getThumb()).resize(300,150).centerCrop().into(viewHolder.img);
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(mContext, ActacteActivity.class);
                    String id=data.getId();
                    intent.putExtra("id",id);
                    mContext.startActivity(intent);
                }
            });
        }
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
}
